package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsBrandMapper;
import com.qf.pojo.DtsBrand;
import com.qf.service.DtsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class DtsBrandServiceImpl implements DtsBrandService {

    @Autowired
    DtsBrandMapper brandMapper;

    /**
     * 通过品牌制造商id查找品牌id
     * @param id
     * @return
     */
    @Override
    public List<Integer> findBrandIdsByAdminId(Integer id) {
        LambdaQueryWrapper<DtsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsBrand::getAdminId,id);
        wrapper.eq(DtsBrand::getDeleted,false);

        List<DtsBrand> brandList = brandMapper.selectList(wrapper);

        //数据转换
        List<Integer> list = brandList.stream().map(brand -> {
            return brand.getId();
        }).collect(Collectors.toList());

        return list;
    }

    /**
     * 查看品牌列表
     * @return
     */
    @Override
    public List<Map<String, Object>> findBrandList() {
        LambdaQueryWrapper<DtsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsBrand::getDeleted,false);

        List<DtsBrand> brandList = brandMapper.selectList(wrapper);

        //数据转换
        List<Map<String, Object>> list = brandList.stream().map(dtsBrand -> {
            Map<String, Object> map = new HashMap<>();
            map.put("value", dtsBrand.getId());
            map.put("label", dtsBrand.getName());

            return map;
        }).collect(Collectors.toList());

        return list;
    }

    @Override
    public DtsBrand findById(Integer brandId) {
        DtsBrand brand = brandMapper.selectById(brandId);
        return brand;
    }
}
